package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into user(username,password,nickname,phone,email,is_active,created_time) values(#{username},#{password},#{nickname},#{phone},#{email},#{isActive},#{createdTime})")
    int addUser(User user);

    @Select("select * from user where username = #{username} and password = #{password}")
    public User findUser(@Param("username")String username, @Param("password") String password);

    @Select("select * from user where email = #{email}")
    public User findUserByEmail(@Param("email") String email);

    // 添加查询所有用户的方法
    @Select("select * from user")
    public List<User> findAllUsers();
    
    // 根据ID查询用户
    @Select("select * from user where user_id = #{userId}")
    User findUserById(@Param("userId") Integer userId);
    
    // 根据邮箱更新密码
    @Update("update user set password = #{password} where email = #{email}")
    public int updatePassword(@Param("password") String password, @Param("email") String email);
    
    // 根据用户ID更新密码
    @Update("update user set password = #{password} where user_id = #{userId}")
    int updatePasswordById(@Param("password") String password, @Param("userId") Integer userId);
    
    // 删除用户
    @Delete("delete from user where user_id = #{userId}")
    int deleteUserById(@Param("userId") Integer userId);
}